// Filename: router.js
define([
    'jquery',
    'underscore',
    'backbone',
    'backbone-relational',
    'GallaryBuilder',
    "basket",
    "BasketBuilder",
    "searchItems"

], function($, _, Backbone, Backbone_relational, GallaryBuilder, Basket, BasketBuilder, SearchItems) {


    var GalleryRouter = Backbone.Router.extend({
        /* define the route and function maps for this router */
        routes:{
            "basket":"buildBasket",
            "about":"showAbout",
            /*Sample usage: http://unicorns.com/#about*/
            "photos/:perPageParam/:currentPageParam":"buildGallery",
            /*This is an example of using a ":param" variable which allows us to match
             any of the components between two URL slashes*/
            /*Sample usage: http://unicorns.com/#photos/5*/
            "search/:query":"searchPhotos",
            /*We can also define multiple routes that are bound to the same map function,
             in this case searchPhotos(). Note below how we're optionally passing in a
             reference to a page number if one is supplied*/
            /*Sample usage: http://unicorns.com/#search/lolcats*/
            /*Sample usage: http://unicorns.com/#search/lolcats*/

            /*As we can see, URLs may contain as many ":param"s as we wish*/
            /*Sample usage: http://unicorns.com/#search/lolcats/p1*/
            "photos/:id/download/*imagePath":"downloadPhoto",
            "itemInfo/:Article":"buildItem",
            "delivery":"delivery",
            "contacts":"contacts",

            /*This is an example of using a *splat. splats are able to match any number of
             URL components and can be combined with ":param"s*/
            /*Sample usage: http://unicorns.com/#photos/5/download/files/lolcat-car.jpg*/
            /*If you wish to use splats for anything beyond default routing, it's probably a good
             idea to leave them at the end of a URL otherwise you may need to apply regular
             expression parsing on your fragment*/
            "*other":"defaultRoute"
            /*This is a default route that also uses a *splat. Consider the
             default route a wildcard for URLs that are either not matched or where
             the user has incorrectly typed in a route path manually*/
            /*Sample usage: http://unicorns.com/#anything*/
        },

        contacts:function (Article) {
            console.log("contacts");

        },

        delivery:function (Article) {
            console.log("delivery");
        },
        buildItem:function (Article) {
            console.log("building item " + Article);

            buildItem(Article);
        },
        buildBasket:function () {
            console.log("building basket");
            buildBasket();

        },

        showAbout:function () {
            console.log("fail");

        },
        buildGallery:function (perPageParam, currentPageParam) {
            GallaryBuilder.initialize(perPageParam,currentPageParam);
            //buildGallery(perPageParam, currentPageParam);
        },
        searchPhotos:function (query, page) {
            SearchItems.initialize(5,0,query);
          //  console.log("Page number: " + page + " of the results for " + query);

        },
        downloadPhoto:function (id, path) {
            console.log("Invalid. You attempted to reach:" + other);
        }
//    defaultRoute:function (other) {
//        console.log("Invalid. You attempted to reach:" + other);
//        myGalleryRouter.navigate('photos/2/0', {trigger:true});
//    }
    });


    var initialize = function(){
        Backbone.emulateHTTP = true;
        Backbone.emulateJSON = true;

        var myGalleryRouter = new GalleryRouter();
        Backbone.history.start();
    };
    return {
        initialize: initialize
    };
});
